import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { HintsService } from '../../../../public/serve/hints/hints.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../../server/server';

import { appProductUrl } from '../../../product.url';
import { product } from '../../../product.data';
import {appSynonymUrl} from '../../../../synonym/synonym.url';

declare var $: any;

@Component({
    selector: 'app-product-indexing-task-check',
    templateUrl: './product-indexing-task-check.component.html'
})
export class ProductIndexingTaskCheckComponent implements OnInit {

    one: any;
    taskData: any;
    checkStatus: number;
    @Output() checkEvent = new EventEmitter<void>();

    constructor(
        private server: Service,
        private request: CudTableService,
        private hintsService: HintsService
    ) { }

    ngOnInit() {
    }

    setData(taskData, status) {
        this.checkStatus = status;
        this.taskData = taskData;
    }

    //修改任务审核状态
    auditTaskStatus() {
        let params = {
            token: product.retrieval.token,
            taskId: this.taskData.taskId,
            checkStatus: this.checkStatus,
            createBy: this.taskData.createBy,
            description: this.taskData.description
        };
        this.request.postRequest(this.server.baseUrl +appProductUrl.auditTask, params).then((res: any) => {
            if (res.result_code === '0000') {
                this.checkEvent.emit();
            }
            this.hintsService.messages(res.message, res.result_code);
            return;
        }).catch((err: any) => {
            this.hintsService.messages("error", "error");
            return;
        });
    }
}
